from django.db import models
import datetime
from django.core.validators import MinValueValidator


# Create your models here.

class User(models.Model):
    common_user = 0
    druger = 1
    manager = 2
    ID_CHOICE = [
        (common_user, "普通用户"),
        (druger, "执业药师"),
        (manager, "管理员")
    ]

    username = models.CharField(max_length=64, null=False, primary_key=True)
    password = models.CharField(max_length=64, null=False)
    identify = models.IntegerField(choices=ID_CHOICE, default=0)


class Drug(models.Model):
    bottle = 0
    bag = 1
    box = 2
    type_Choice = [
        (bottle, "瓶装"),
        (bag, "袋装"),
        (box, "盒装")
    ]

    produce_No = models.CharField(max_length=1024, primary_key=True)
    dName = models.CharField(max_length=1024, null=False)
    dNum = models.IntegerField(null=False)
    produce_Date = models.DateField(null=False)
    save_Date = models.IntegerField(null=False)
    dType = models.IntegerField(null=False, choices=type_Choice, default=0)
    manf = models.CharField(max_length=1024, null=False)


class saleSlip(models.Model):
    sid = models.CharField(max_length=1024, primary_key=True)
    saleDate = models.DateField(null=False, default=datetime.date.today)


class purchaseOrder(models.Model):
    pid = models.CharField(max_length=1024, primary_key=True)
    purchaseDate = models.DateField(null=False, default=datetime.date.today)

class sale(models.Model):
    sid = models.ForeignKey(saleSlip, on_delete=models.CASCADE)
    dno = models.ForeignKey(Drug, on_delete=models.CASCADE)
    num = models.IntegerField(null=False, validators=[MinValueValidator(1)])

class purchase(models.Model):
    pid = models.ForeignKey(purchaseOrder, on_delete=models.CASCADE)
    dno = models.ForeignKey(Drug, on_delete=models.CASCADE)
    num = models.IntegerField(null=False, validators=[MinValueValidator(1)])